#ifndef _C_DRAW_MODEL_H_
#define _C_DRAW_MODEL_H_

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/select.h>

#include "SMATModel.hh"

#include "pose3d.h"
#include "view.h"
#include "model.h"


//     //#define NLINEAS_EJES 7
#define OX 125
#define OY 75
#define OZ 0
#define ZPOINT -1
#define SIZE_EJES 60.0F


class CDrawModel  {
 public:
    CvFont fontmod;
    CvFont fontmod2;
    
    CvMat *ejes2D;
    CvMat *ejes3D;
    CvMat *translation2;
    CvMat *ejes3DZ;
    CvMat rodriguesZ;
    CvMat *rotation;

 public:
    
    CDrawModel()
    {
	double hScale=0.57, vScale = 0.567;
	int lineWidth = 1;
	cvInitFont(&fontmod, CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, hScale,vScale,0,lineWidth);
	cvInitFont(&fontmod2, CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, 1 ,1,0,2);

	float ejes_float[8][3] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, ZPOINT}, 
				  {0.2F, 0.2F, ZPOINT+0.2F}, {-0.2F, 0.2F, ZPOINT+0.2F},
				  {0.2F, -0.2F, ZPOINT+0.2F}, {-0.2F, -0.2F, ZPOINT+0.2F}};
			      
	rotation = cvCreateMat(3,3,CV_32FC1);
	ejes2D = cvCreateMat(8, 2, CV_32FC1);
	CvMat ejes3D2 = cvMat(8, 3, CV_32FC1, ejes_float);
	ejes3D = cvCloneMat(&ejes3D2);
	ejes3DZ = cvCreateMat(ejes3D->rows, 1, CV_32FC1);
	cvGetRow(rotation, &rodriguesZ, 2);

	cvScale(ejes3D, ejes3D, SIZE_EJES);

	translation2 = cvCreateMat(3,1,CV_32FC1);
	cvZero(translation2);

    }

    ~CDrawModel()
    {
	cvReleaseMat(&translation2);
    }

    static int compareZ_line_t( const void* _a, const void* _b);

    void DrawModel(CView &view, CvMat * points, CvMat *mask_show,
		   CvMat * lineas, 
		   IplImage * image, CvMat *mask_color=NULL, 
		   int index_point=-1,
		   CvScalar color=CV_RGB(0,0,155));

    void DrawModel3D(CModel3D &model, CView &view, 
		     IplImage * image, CvMat *mask_color=NULL, 
		     int index_point=-1,
		     CvScalar color=CV_RGB(0,0,155));

    void DrawModel3D(CView2D &view, 
		     IplImage * image, CvMat *mask_color=NULL, 
		     int index_point=-1,
		     CvScalar color=CV_RGB(0,0,255));

    void DrawModel(CView2D &view, 
		   IplImage * image, CvMat *mask_color=NULL, 
		   int index_point=-1,
		   CvScalar color=CV_RGB(155,0,0));
};


#endif
